class ScreenOver extends egret.DisplayObjectContainer {
    private mainWapper: MainWapper
    private btnOff = false
    private miva_num = 0
    public constructor() {
        super()
        this.once(egret.Event.ADDED_TO_STAGE, this.init, this)
    }
    private init() {
        this.createMW()
        this.createUI()
        this.mainWapper.addEventListener('setting_over', () => {
            this.miva_num++
            if (this.miva_num < 2) return console.log('wait')
            this.btnOff = false
            // 在这里进行截图
            Utils.shareImage(this.mainWapper)
            // this.mainWapper.alpha = 0
        }, this)
    }
    private createMW() {
        this.mainWapper = new MainWapper()
        this.addChild(this.mainWapper)
        this.mainWapper.anchorOffsetX = this.mainWapper.width / 2
        this.mainWapper.x = this.stage.stageWidth / 2
        this.mainWapper.y = 50
    }
    private createUI() {
        const container = new egret.Sprite()
        this.addChild(container)
        container.width = this.mainWapper.width + 40

        const tip = Utils.createBitmapByName('tip_save_png')
        container.addChild(tip)
        tip.anchorOffsetX = tip.width / 2
        tip.x = container.width / 2

        const group_btn = new egret.Sprite()
        container.addChild(group_btn)
        group_btn.width = container.width
        group_btn.y = tip.y + tip.height + 10
        group_btn.addChild(this.createBtnResetCL(group_btn))
        group_btn.addChild(this.createBtnResetBG(group_btn))

        container.anchorOffsetX = container.width / 2
        container.x = this.stage.stageWidth / 2
        container.y = this.mainWapper.y + this.mainWapper.height + 50
    }

    private createBtnResetCL(container): egret.Bitmap {
        const btn = Utils.createBitmapByName('btn_reset_png')
        btn.touchEnabled = true
        btn.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
            console.log("点击了按钮")
            if (this.btnOff) return console.log('wait')
            this.btnOff = true
            this.mainWapper.alpha = 1
            $('#divImage').hide()
            this.mainWapper.createCL()
        }, this)
        return btn
    }
    private createBtnResetBG(container): egret.Bitmap {
        const btn = Utils.createBitmapByName('btn_reset_image_png')
        btn.anchorOffsetX = btn.width
        btn.x = container.width
        btn.touchEnabled = true
        btn.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
             window.location.reload();
            // if (this.btnOff) return console.log('wait')
            // this.btnOff = true
            // this.mainWapper.alpha = 1
            // $('#divImage').hide()
            // this.mainWapper.resetBG()
        }, this)
        return btn
    }
}